home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / PC Card Manager / CIncludes / Threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-25  |  9.2 KB  |  246 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        Threads.h
  3.  
  4.      Contains:    Thread Manager Interfaces.
  5.  
  6.      Version:    System 7.5
  7.  
  8.      DRI:        Jeff Gobel
  9.  
  10.      Copyright:    © 1984-1996 by Apple Computer, Inc.
  11.                  All rights reserved.
  12.  
  13.      Warning:    *** APPLE INTERNAL USE ONLY ***
  14.                  This file may contain unreleased API's
  15.  
  16.      BuildInfo:    Built by:            SuperMario Build Daemon
  17.                  With Interfacer:    2.0d11   (PowerPC native)
  18.                  From:                Threads.i
  19.                      Revision:        19
  20.                      Dated:            3/15/96
  21.                      Last change by:    JGG
  22.                      Last comment:    Backed out NewNamedThread(), GetThreadName(), and
  23.  
  24.      Bugs:        Report bugs to Radar component “System Interfaces”, “Latest”
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __THREADS__
  29. #define __THREADS__
  30.  
  31. #ifndef __ERRORS__
  32. #include <Errors.h>
  33. #endif
  34. #ifndef __MEMORY__
  35. #include <Memory.h>
  36. #endif
  37.  
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41.  
  42. #if PRAGMA_IMPORT_SUPPORTED
  43. #pragma import on
  44. #endif
  45.  
  46. #if PRAGMA_ALIGN_SUPPORTED
  47. #pragma options align=mac68k
  48. #endif
  49.  
  50. #if FOR_SYSTEM7_AND_SYSTEM8_COOPERATIVE
  51. /* Thread states */
  52. typedef unsigned short ThreadState;
  53.  
  54. enum {
  55.     kReadyThreadState            = 0,
  56.     kStoppedThreadState            = 1,
  57.     kRunningThreadState            = 2
  58. };
  59.  
  60. /* Error codes have been meoved to Errors.(pah) */
  61. /* Thread environment characteristics */
  62. typedef void *ThreadTaskRef;
  63. /* Thread characteristics */
  64. typedef unsigned long ThreadStyle;
  65.  
  66. enum {
  67.     kCooperativeThread            = 1L << 0,
  68.     kPreemptiveThread            = 1L << 1
  69. };
  70.  
  71. /* Thread identifiers */
  72. typedef unsigned long ThreadID;
  73.  
  74. enum {
  75.     kNoThreadID                    = 0,
  76.     kCurrentThreadID            = 1,
  77.     kApplicationThreadID        = 2
  78. };
  79.  
  80. /* Options when creating a thread */
  81. typedef unsigned long ThreadOptions;
  82.  
  83. enum {
  84.     kNewSuspend                    = (1 << 0),
  85.     kUsePremadeThread            = (1 << 1),
  86.     kCreateIfNeeded                = (1 << 2),
  87.     kFPUNotNeeded                = (1 << 3),
  88.     kExactMatchThread            = (1 << 4)
  89. };
  90.  
  91. /* Information supplied to the custom scheduler */
  92. struct SchedulerInfoRec {
  93.     unsigned long                     InfoRecSize;
  94.     ThreadID                         CurrentThreadID;
  95.     ThreadID                         SuggestedThreadID;
  96.     ThreadID                         InterruptedCoopThreadID;
  97. };
  98. typedef struct SchedulerInfoRec SchedulerInfoRec;
  99.  
  100. typedef SchedulerInfoRec *SchedulerInfoRecPtr;
  101. #if GENERATING68K && GENERATINGCFM
  102. /*
  103.     The following UniversalProcPtrs are for CFM-68k compatiblity with
  104.     the implementation of the Thread Manager.
  105. */
  106. typedef UniversalProcPtr ThreadEntryProcPtr;
  107. typedef UniversalProcPtr ThreadSchedulerProcPtr;
  108. typedef UniversalProcPtr ThreadSwitchProcPtr;
  109. typedef UniversalProcPtr ThreadTerminationProcPtr;
  110. typedef UniversalProcPtr DebuggerNewThreadProcPtr;
  111. typedef UniversalProcPtr DebuggerDisposeThreadProcPtr;
  112. typedef UniversalProcPtr DebuggerThreadSchedulerProcPtr;
  113. enum {
  114.     uppThreadEntryProcInfo = kPascalStackBased
  115.          | RESULT_SIZE(SIZE_CODE(sizeof(void*)))
  116.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void*))),
  117.     uppThreadSchedulerProcInfo = kPascalStackBased
  118.          | RESULT_SIZE(SIZE_CODE(sizeof(ThreadID)))
  119.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SchedulerInfoRecPtr))),
  120.     uppThreadSwitchProcInfo = kPascalStackBased
  121.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID)))
  122.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void*))),
  123.     uppThreadTerminationProcInfo = kPascalStackBased
  124.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID)))
  125.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void*))),
  126.     uppDebuggerNewThreadProcInfo = kPascalStackBased
  127.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID))),
  128.     uppDebuggerDisposeThreadProcInfo = kPascalStackBased
  129.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ThreadID))),
  130.     uppDebuggerThreadSchedulerProcInfo = kPascalStackBased
  131.          | RESULT_SIZE(SIZE_CODE(sizeof(ThreadID)))
  132.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SchedulerInfoRecPtr)))
  133. };
  134. #define NewThreadEntryProc(userRoutine)                (ThreadEntryProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadEntryProcInfo, GetCurrentArchitecture())
  135. #define NewThreadSchedulerProc(userRoutine)            (ThreadSchedulerProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadSchedulerProcInfo, GetCurrentArchitecture())
  136. #define NewThreadSwitchProc(userRoutine)            (ThreadSwitchProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadSwitchProcInfo, GetCurrentArchitecture())
  137. #define NewThreadTerminationProc(userRoutine)        (ThreadTerminationProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppThreadTerminationProcInfo, GetCurrentArchitecture())
  138. #define NewDebuggerNewThreadProc(userRoutine)        (DebuggerNewThreadProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerNewThreadProcInfo, GetCurrentArchitecture())
  139. #define NewDebuggerDisposeThreadProc(userRoutine)    (DebuggerDisposeThreadProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerDisposeThreadProcInfo, GetCurrentArchitecture())
  140. #define NewDebuggerThreadSchedulerProc(userRoutine)    (DebuggerThreadSchedulerProcPtr) NewRoutineDescriptor((ProcPtr)(userRoutine), uppDebuggerThreadSchedulerProcInfo, GetCurrentArchitecture())
  141. #else
  142. /*
  143.     The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  144.     of differences between 680x0 and PowerPC runtime architectures with regard to
  145.     the implementation of the Thread Manager.
  146. */
  147. /* Prototype for thread's entry (main) routine */
  148. typedef void *voidPtr;
  149. typedef pascal voidPtr (*ThreadEntryProcPtr)(void *threadParam);
  150. /* Prototype for custom thread scheduler routine */
  151. typedef pascal ThreadID (*ThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  152. /* Prototype for custom thread switcher routine */
  153. typedef pascal void (*ThreadSwitchProcPtr)(ThreadID threadBeingSwitched, void *switchProcParam);
  154. /* Prototype for thread termination notification routine */
  155. typedef pascal void (*ThreadTerminationProcPtr)(ThreadID threadTerminated, void *terminationProcParam);
  156. /* Prototype for debugger NewThread notification */
  157. typedef pascal void (*DebuggerNewThreadProcPtr)(ThreadID threadCreated);
  158. /* Prototype for debugger DisposeThread notification */
  159. typedef pascal void (*DebuggerDisposeThreadProcPtr)(ThreadID threadDeleted);
  160. /* Prototype for debugger schedule notification */
  161. typedef pascal ThreadID (*DebuggerThreadSchedulerProcPtr)(SchedulerInfoRecPtr schedulerInfo);
  162. #endif
  163. /* Thread Manager routines */
  164. extern pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  165.  THREEWORDINLINE(0x303C, 0x0501, 0xABF2);
  166.  
  167. extern pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  168.  THREEWORDINLINE(0x303C, 0x0402, 0xABF2);
  169.  
  170. extern pascal OSErr GetSpecificFreeThreadCount(ThreadStyle threadStyle, Size stackSize, short *freeCount)
  171.  THREEWORDINLINE(0x303C, 0x0615, 0xABF2);
  172.  
  173. extern pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  174.  THREEWORDINLINE(0x303C, 0x0413, 0xABF2);
  175.  
  176. extern pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  177.  THREEWORDINLINE(0x303C, 0x0414, 0xABF2);
  178.  
  179. extern pascal OSErr NewThread(ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade)
  180.  THREEWORDINLINE(0x303C, 0x0E03, 0xABF2);
  181.  
  182. extern pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  183.  THREEWORDINLINE(0x303C, 0x0504, 0xABF2);
  184.  
  185. extern pascal OSErr YieldToThread(ThreadID suggestedThread)
  186.  THREEWORDINLINE(0x303C, 0x0205, 0xABF2);
  187.  
  188. extern pascal OSErr YieldToAnyThread(void )
  189.  FOURWORDINLINE(0x42A7, 0x303C, 0x0205, 0xABF2);
  190.  
  191. extern pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  192.  THREEWORDINLINE(0x303C, 0x0206, 0xABF2);
  193.  
  194. extern pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  195.  THREEWORDINLINE(0x303C, 0x0407, 0xABF2);
  196.  
  197. extern pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  198.  THREEWORDINLINE(0x303C, 0x0508, 0xABF2);
  199.  
  200. extern pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  201.  THREEWORDINLINE(0x303C, 0x0512, 0xABF2);
  202.  
  203. extern pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  204.  THREEWORDINLINE(0x303C, 0x0209, 0xABF2);
  205.  
  206. extern pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  207.  THREEWORDINLINE(0x303C, 0x070A, 0xABF2);
  208.  
  209. extern pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  210.  THREEWORDINLINE(0x303C, 0x0611, 0xABF2);
  211.  
  212. extern pascal OSErr ThreadBeginCritical(void )
  213.  THREEWORDINLINE(0x303C, 0x000B, 0xABF2);
  214.  
  215. extern pascal OSErr ThreadEndCritical(void )
  216.  THREEWORDINLINE(0x303C, 0x000C, 0xABF2);
  217.  
  218. extern pascal OSErr SetDebuggerNotificationProcs(DebuggerNewThreadProcPtr notifyNewThread, DebuggerDisposeThreadProcPtr notifyDisposeThread, DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  219.  THREEWORDINLINE(0x303C, 0x060D, 0xABF2);
  220.  
  221. extern pascal OSErr GetThreadCurrentTaskRef(ThreadTaskRef *threadTRef)
  222.  THREEWORDINLINE(0x303C, 0x020E, 0xABF2);
  223.  
  224. extern pascal OSErr GetThreadStateGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  225.  THREEWORDINLINE(0x303C, 0x060F, 0xABF2);
  226.  
  227. extern pascal OSErr SetThreadReadyGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToSet)
  228.  THREEWORDINLINE(0x303C, 0x0410, 0xABF2);
  229.  
  230. #endif
  231.  
  232. #if PRAGMA_ALIGN_SUPPORTED
  233. #pragma options align=reset
  234. #endif
  235.  
  236. #if PRAGMA_IMPORT_SUPPORTED
  237. #pragma import off
  238. #endif
  239.  
  240. #ifdef __cplusplus
  241. }
  242. #endif
  243.  
  244. #endif /* __THREADS__ */
  245.  
  246.